import logging.handlers
import os


def getFileLogger(filepath, **kwargs):
    dir_name = os.path.dirname(filepath)
    if not os.path.isdir(dir_name):
        os.makedirs(dir_name)
    log_name, _ = os.path.basename(filepath).split('.')
    handler = logging.handlers.TimedRotatingFileHandler(
        filename=filepath, when=kwargs.get("when", "D"), interval=kwargs.get("interval", 1),
        backupCount=kwargs.get("backupCount", 7), encoding="utf-8"
    )
    handler.suffix = "%Y%m%d"
    handler.setFormatter(logging.Formatter(kwargs.get("outputFormat", "%(asctime)s-%(levelname)s-%(message)s")))
    logger = logging.getLogger(log_name)
    logger.addHandler(handler)
    return logger
